﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class ComfirmOrder : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            SqlCommand cmdSelect, cmdSeller;
            SqlDataReader dtrSelect, dtrSeller;
            conn.Open();
          
         //cmdSelect = new SqlCommand("SELECT * FROM Products p, Transactions t, Transactions_Products tp, Users u, Shipping_Details sd WHERE p.p_id=tp.p_id AND t.t_id=tp.t_id AND u.u_id=t.u_id AND t.s_id=sd.s_id AND t.t_id=@tid", conn);

            cmdSelect = new SqlCommand("SELECT * FROM Products p, Transactions t,Transactions_Products tp WHERE tp.p_id=p.p_id AND tp.t_id=t.t_id AND t.t_id=@TID", conn);
            cmdSelect.Parameters.AddWithValue("@TID", Session["TransactionID"].ToString());
            dtrSelect = cmdSelect.ExecuteReader();

            Repeater1.DataSource = dtrSelect;
            Repeater1.DataBind();
            dtrSelect.Close();
            
            dtrSelect = cmdSelect.ExecuteReader();
            dtrSelect.Read();
            lblTotal.Text =dtrSelect["t_total"].ToString();

            dtrSelect.Close();

            //Copy from select payment
           
            String ReferenceNumber = Session["ReferenceNumber"].ToString();
            String TotalOrder = Session["TotalOrder"].ToString();
            String SellerID = Session["SellerID"].ToString();
            String SellerAccount = "";

            cmdSeller = new SqlCommand("SELECT * FROM Users where u_id=@id", conn);
            cmdSeller.Parameters.AddWithValue("@id", SellerID);
            dtrSeller = cmdSeller.ExecuteReader();
            dtrSeller.Read();

            SellerAccount = dtrSeller["u_email"].ToString();

            dtrSeller.Close();
            conn.Close();

            //Response.Write("email " + SellerAccount + "-----Reference Number:" + ReferenceNumber + "----Amount" + TotalOrder);

            Label4.Text = "  <input type='hidden' name='business' value='" + SellerAccount + "' /><input type='hidden' name='item_name' value='" + ReferenceNumber + "' /><input type='hidden' name='amount' value='" + TotalOrder + "'  /> ";

            conn.Close();
        }

        public double processData(object quantity, object price)
        {
            double total = int.Parse(quantity.ToString()) * double.Parse(price.ToString());
            return total;
        }
    }
}